package com.jf3q.iot.controller;

import com.jf3q.iot.dto.ResultBean;
import com.jf3q.iot.service.IotDeviceService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author:xiaojie
 * @create: 2023-06-01 08:30
 * @Description:
 */
@RestController
@RequestMapping("/device")
public class DeviceController {

    @Resource
    IotDeviceService iotDeviceService;


    /**
     * 对电表的操作-拉闸 合闸  拉a路  拉b路等操作
     * @param operationType
     * @param id
     * @return
     */
    @GetMapping("/electricity/{id}")
    public ResultBean operationElectricity(String operationType,@PathVariable Integer id){

        iotDeviceService.operationElectricity(operationType,id);

        return ResultBean.success("操作成功",null);
    }


    /**
     * 只是为了测试获取电表的余额（实际是用定时任务
     * 每隔两小时查下电表余额，这个过程叫做抄表）
     *
     * 如果电表余额不足就要拉闸
     * @return
     */
    @GetMapping("/electricity/money")
    public ResultBean money(){
        iotDeviceService.meterJob();
        return ResultBean.success("操作成功",null);
    }

}
